import bpy
from bpy.types import Panel


def top_bar(self: bpy.types.Panel, context: "bpy.types.Object"):
    from ..ops.render import SwitchRenderUi
    layout = self.layout
    region = context.region
    name = self.__class__.__name__

    def ops(lay):
        lay.operator(SwitchRenderUi.bl_idname,
                     icon='SHADING_RENDERED',
                     text='',
                     emboss=False,
                     ).popup_window = True

    if name == 'USERPREF_MT_editor_menus':
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        ops(layout)
    elif name == 'USERPREF_PT_save_preferences':
        ops(layout.row())
    elif name == 'TOPBAR_MT_editor_menus':
        if region.alignment == 'RIGHT':
            ...
        else:
            ops(layout)


class UserPrefRight(Panel):
    bl_idname = "USERPREF_PT_right"
    bl_label = "e"
    bl_space_type = 'PREFERENCES'
    bl_region_type = 'TOOL_HEADER'

    def draw(self, context):
        layout = self.layout
        layout.label('emm')


class_tuple = (
)
reg_class, unreg_class = bpy.utils.register_classes_factory(class_tuple)


def register():
    reg_class()
    bpy.types.TOPBAR_MT_editor_menus.append(top_bar)

    bpy.types.USERPREF_MT_editor_menus.append(top_bar)

    bpy.types.USERPREF_PT_save_preferences.append(top_bar)


def unregister():
    unreg_class()

    bpy.types.TOPBAR_MT_editor_menus.remove(top_bar)

    bpy.types.USERPREF_MT_editor_menus.remove(top_bar)

    bpy.types.USERPREF_PT_save_preferences.remove(top_bar)
